package il.ac.technion.wiki.api.expressions;

import il.ac.technion.wiki.api.search.Hit;
import il.ac.technion.wiki.api.wikidocument.WikiDocument;
import il.ac.technion.wiki.impl.search.WikiIndexSearcher;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;

public class NotOpTest {

	@Test
	public void testEvaluate() {
		WikiIndexSearcher mis = new WikiIndexSearcher();
		createDocs(mis);
		NotOp not = new NotOp();
		
		not.setElement(new Term("b"));
		List<Hit> hits = not.getHits(mis);
		Assert.assertEquals(4, hits.size());
		
		not.setElement(new Term("e"));
		hits = not.getHits(mis);
		Assert.assertEquals(2, hits.size());
		
		not.setElement(new Term("k"));
		hits = not.getHits(mis);
		Assert.assertEquals(7, hits.size());
	
	}
	@Test
	public void testEvaluate2() {
		WikiIndexSearcher mis = new WikiIndexSearcher();
		createDocs(mis);
		NotOp not = new NotOp();
		not.setElement(new Term("b"));
		NotOp notFather = new NotOp();
		notFather.setElement(not);
		List<Hit> hits = notFather.getHits(mis);
		Assert.assertEquals(3, hits.size());
		
		not.setElement(new Term("l"));
		hits = notFather.getHits(mis);
		Assert.assertEquals(0, hits.size());
		
	}
	
	private void createDocs(WikiIndexSearcher mis){
		mis.addDocument(new WikiDocument("1" , "f f g d d b e"));
		mis.addDocument(new WikiDocument("2" , "fff  f e"));
		mis.addDocument(new WikiDocument("3" , "c c c b b e"));
		mis.addDocument(new WikiDocument("4" , "aaa"));
		mis.addDocument(new WikiDocument("5" , "fgb e"));
		mis.addDocument(new WikiDocument("6" , " f f f f"));
		mis.addDocument(new WikiDocument("7" , "b c d e f g h i"));
	}
}
